/*
 * BufferManager.cpp
 *
 * Created on: 09-Oct-2009
 * Author: Atul Shukla (atul.shukla@iiitb.net)
 */
#include<iostream>
#include<stdio.h>
#include"BufferManager.h"

void BufferManagerUI::bmUI(BufferManager* bm,int n) {

	Status s;
    //int n :: no of frames
	char ch;
	int temp;
	do {
		cout << "1. View Frame\n";
		cout << "2. View Buffer Status\n";
		cout << "3. Read Page from Disk\n";
		cout << "4. Write Page to Disk\n";
		cout << "5. Hit Ratio\n";
		cout << "6. Commit Buffer\n";
		cout << "7. Close\n";
		cout << "0. Exit\n";
		cout << "Input your choice:: ";
		cin >> ch;

		switch (ch) {
		case '1':
			if (bm != 0) {
				cout << "\nInput Frame No::";
				cin >> temp;
				if (temp >= 0 && temp <= n)
					bm->viewFrame(temp);
				else
					cout << "Frame Not Availale";
			} else
				cout << "Buffer Not Initialised";
			break;
		case '2':
			if (bm != 0) {
				bm->viewBufferStatus();

			} else
				cout << "Buffer Not Initialised";
			break;
		case '3':
			if (bm != 0) {
				Page* p;
				p = new Page();
				cout << "\nInput Page No::";
				cin >> temp;
				bm->pinPage(temp, p);

			} else
				cout << "Buffer Not Initialised";
			break;
		case '4':
			if (bm != 0) {
				cout << "\nInput Frame No::";
				cin >> temp;
			} else
				cout << "Buffer Not Initialised";
			break;
		case '5':
			if (bm != 0) {
				cout << bm->getHitRatio() << "\n";
			} else
				cout << "Buffer Not Initialised";
			break;
		case '6':
			if (bm != 0) {
				bm->flushAllPages();
				cout << "Commited\n";
			} else
				cout << "Buffer Not Initialised";
			break;
		case '7':
			if (bm != 0) {
				bm->~BufferManager();
				bm = 0;
			} else
				cout << "Buffer Not Initialised";

			break;
		default:
			break;
		}
	} while (ch != '0');//infinite loop

	return;

}

